/**
 * 
 */
package com.manage.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.AppSdkManager;
import com.manage.cache.CpAppInfoManager;
import com.manage.cache.CpInfoManager;
import com.manage.cache.SdkProvidersManager;
import com.manage.model.AppSdk;
import com.manage.model.CpAppInfo;
import com.manage.model.CpInfo;
import com.manage.model.SdkProviders;


public class AppSdkAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public AppSdkAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<AppSdk> list;
	private AppSdk       model;
	private String        type;
	private CpAppInfo appinfo;
	private CpInfo cpinfo;
	private List<SdkProviders> sdklist;
	private String sdkid;
	public String show()
	{
		cpinfo = CpInfoManager.getInstance().getCpInfo(model.getCpid());
		appinfo = CpAppInfoManager.getInstance().getCpAppInfoByAppNumber(model.getAppnumber());
		list = AppSdkManager.getInstance().getAppSdkByAppnumber(model.getAppnumber());
		sdklist = SdkProvidersManager.getInstance().getSdkProviders();
		return SUCCESS;
	}
	
	public String save()
	{
		cpinfo = CpInfoManager.getInstance().getCpInfo(model.getCpid());
		appinfo = CpAppInfoManager.getInstance().getCpAppInfoByAppNumber(model.getAppnumber());
		list = new ArrayList<AppSdk>();
		if(sdkid!=null && !"".equals(sdkid)&&!"null".equals(sdkid))
		{
			String []id = sdkid.split(", ");
			AppSdk appsdkmodel = null;
			for(int i =0;i<id.length;i++)
			{
				appsdkmodel = new AppSdk();
				appsdkmodel.setCpid(model.getCpid());
				appsdkmodel.setAppnumber(model.getAppnumber());
				appsdkmodel.setSdkid(Integer.parseInt(id[i]));
				String sdksort = getRequest().getParameter("sdksort_"+id[i]);
				if(sdksort!=null && sdksort.trim().length()>0)
				{
					appsdkmodel.setSdksort(Integer.parseInt(sdksort));
				}
				else
				{
					appsdkmodel.setSdksort(0);
				}
				list.add(appsdkmodel);
			}
		}
		
		AppSdkManager.getInstance().saveAppSdk(operator, type, list,model.getAppnumber());
		return SUCCESS;
	}

	public List<AppSdk> getList() {
		return list;
	}

	public void setList(List<AppSdk> list) {
		this.list = list;
	}

	public AppSdk getModel() {
		return model;
	}

	public void setModel(AppSdk model) {
		this.model = model;
	}

	public List<SdkProviders> getSdklist() {
		return sdklist;
	}

	public void setSdklist(List<SdkProviders> sdklist) {
		this.sdklist = sdklist;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public CpAppInfo getAppinfo() {
		return appinfo;
	}

	public void setAppinfo(CpAppInfo appinfo) {
		this.appinfo = appinfo;
	}

	public CpInfo getCpinfo() {
		return cpinfo;
	}

	public void setCpinfo(CpInfo cpinfo) {
		this.cpinfo = cpinfo;
	}

	public String getSdkid() {
		return sdkid;
	}

	public void setSdkid(String sdkid) {
		this.sdkid = sdkid;
	}
	
}
